#!/bin/bash
source /etc/profile
#/usr/local/resin/bin/resin.sh -server a start
#############################################################################################
##
##  Description: rs a start status stop
##	Version :    v-0.1
##	Date:	     2014-04-27
##  author:  	 huzhirong
##  From:	     datarsync
## 
##############################################################################################
HTTPD_SH="/usr/local/resin/bin/resin.sh"
#webservice的resin配置
WEBSERVICE_CONF="/usr/local/resin/conf/resin.xml"
WEBSERVICE_SERVS=("webserivce" "webadmin")

function operateResin(){	
	if [ $# -ne 3 ] ; then
	   echo "Usage:$0 conf_file start|restart|stop server" 
	   exit 1;
	fi
    conf_file="$1"
    action="$2"
	server="$3"
    if [ ! -f ${conf_file} ]; then
        echo "resin conf ${conf_file}  not exists!";
		exit 1;
    fi
	case "${action:-''}" in
	start)
		echo "start resin.  /bin/bash ${HTTPD_SH} -conf ${conf_file} -server ${server} start"
		/bin/bash ${HTTPD_SH} -conf ${conf_file} -server ${server} start 		
	;;
	restart)
		echo "restart resin.  /bin/bash ${HTTPD_SH} -conf ${conf_file} -server ${server} restart "
		/bin/bash ${HTTPD_SH} -conf ${conf_file} -server ${server} restart	
	;;
	stop)
		echo "stop resin.   /bin/bash ${HTTPD_SH} -conf ${conf_file} -server ${server} stop	"
		/bin/bash ${HTTPD_SH} -conf ${conf_file} -server ${server} stop			
	;;
	*)
		echo "Usage:$0 conf_file start|restart|stop server" 
		exit 1
	;;
	esac	
}

action="$1"
server="$2"

	if [ -z ${server} ];
	then
		for server in ${WEBSERVICE_SERVS[@]} ; do
		   operateResin "${WEBSERVICE_CONF}" "$action" "${server}"
		done
	else
		operateResin "${WEBSERVICE_CONF}" "$action" "${server}"
	fi

#/bin/bash /etc/init.d/resin $1

